new Vue({
  el: '#app',
  data() {
    return {
      form: {
        serachKey: "",
        page: 1,			//页数
        limit: 10			//每页数据条数
      },
      formData: {},
      tableData: [{}],		//表格数据
      total: 1,
      dialogForm: false,
      title: '',
      multipleSelection: []
    }
  },
  mounted() {
    this.getList1()
  },
  computed: {
    // formatTime() {
    //   return function (time) {
    //     let d = new Date(parseInt(time));
    //     return `${d.getFullYear()}-${d.getMonth() + 1
    //       }-${d.getDate()} ${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}`;
    //   };
    // },

  },
  methods: {

    onSerach() {				//查询方法
      console.log("搜搜")
    },
    addContract() {
      console.log("跳转")
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
    },
    handleCurrentChange(val) {
      this.form.page = val;
    },
    getList1() {
      let _this = this
      $.ajax({
        type: 'POST',
        data: { token: $.cookie("token") },
        url: DomainName + '/SalesOrderAllAction',
        success: function (data) {
          data = data.filter(function (item) {
            return item.Refund_Type == '1';
          })
          _this.tableData = data;
          console.log(_this.tableData)
          _this.total = _this.tableData.length
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
    },
    // getList() {     //换页方法
    //   let _this = this
    //   $.ajax({
    //     type: 'POST',
    //     //	url: "../getContractListByConditionAction",
    //     url: "../getListByTableNameAction",
    //     data: {
    //       Data: "enterprise_info"
    //     },
    //     complete: function (XMLHttpRequest) {
    //       _this.loading = false
    //       if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
    //         window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
    //       }
    //     },
    //     success: function (Result) {
    //       console.log(Result);
    //       _this.tableData = Result      //将获取的数据存到表格数据中
    //     },
    //     dataType: "json"
    //   });
    // },
    addEnterprise() {
      window.location.href = './Add.html'
    },
    accMul(arg1, arg2) {
      let m = 0, s1 = arg1.toString(), s2 = arg2.toString();
      try { m += s1.split(".")[1].length } catch (e) { }
      try { m += s2.split(".")[1].length } catch (e) { }
      return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
    },
    // 新通过退款
    isRefund(Sales_Order_SerialNumber) {
      let _this = this
      this.$confirm('通过退款申请，将开始退款, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        $.ajax({
          type: 'POST',
          data: {
            Sales_Order_SerialNumber,
            Type: '1',
            token: $.cookie("token")
          },
          url: DomainName + '/getChatRefundCheckAction',
          success: function (data) {
            console.log(data)
            if (data.Status == "success") {
              _this.$message({
                type: 'success',
                message: '退款成功'
              });
              _this.getList1()
            } else if (data.Status == "PROCESSING") {
              _this.$message({
                type: 'success',
                message: '退款已提交,等待审核'
              });
              _this.getList1()
            }
          },
          complete: function (XMLHttpRequest) {
            _this.loading = false
            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
              window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            }
          },
          dataType: "json"
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消！'
        });
      });
    },
    // 新拒绝退款
    isNorefund(Sales_Order_SerialNumber) {
      let _this = this
      this.$prompt('请输入拒绝原因，如线下沟通则说明', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /^(?!\s*$).+/,
        inputErrorMessage: '原因不能由零个或多个空格组成',
        type: 'warning',
      }).then(({ value }) => {
        $.ajax({
          type: 'POST',
          url: DomainName + '/getChatRefundCheckAction',
          data: {
            Sales_Order_SerialNumber,
            Type: '2',
            Cause: value,
            token: $.cookie("token")
          },
          success: function (data) {
            if (data.Status == "success") {
              _this.$message({
                type: 'info',
                message: '已拒绝申请！'
              });
              _this.getList1()
            }
          },
          complete: function (XMLHttpRequest) {
            _this.loading = false
            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
              window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            }
          },
          dataType: "json"
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消！'
        });
      });
    },
    // 旧通过退款
    refund(Sales_Order_SerialNumber) {
      let _this = this
      this.$confirm('通过退款申请，将开始退款, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        $.ajax({
          type: 'POST',
          data: {
            Sales_Order_SerialNumber,
          },
          url: DomainName + '/CollectionById',
          success: function (data) {
            if (data.length == 1) {
              _this.FuyouRefund(data[0], Sales_Order_SerialNumber);
            } else {
              _this.$message({
                type: 'info',
                message: '该订单未付款！'
              });
            }
          },
          complete: function (XMLHttpRequest) {
            _this.loading = false
            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
              window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            }
          },
          dataType: "json"
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消！'
        });
      });
    },
    // 旧拒绝退款
    Norefund(Sales_Order_SerialNumber) {
      let _this = this
      this.$prompt('请输入拒绝原因，如线下沟通则说明', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /^(?!\s*$).+/,
        inputErrorMessage: '原因不能由零个或多个空格组成',
        type: 'warning',
      }).then(({ value }) => {
        $.ajax({
          type: 'POST',
          data: {
            sales_order: Sales_Order_SerialNumber,
            cause: value
          },
          url: DomainName + '/NoClientRefund',
          success: function (data) {
            if (data.Status == "success") {
              _this.$message({
                type: 'info',
                message: '已拒绝申请！'
              });
              _this.getList1()
            }
          },
          complete: function (XMLHttpRequest) {
            _this.loading = false
            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
              window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            }
          },
          dataType: "json"
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消！'
        });
      });
    },
    FuyouRefund(data, Sales_Order_SerialNumber) {
      let _this = this
      $.ajax({
        type: 'POST',
        data: {
          mchnt: data.mchnt_order_no,//商户订单号
          Sales_Order_SerialNumber,//销售订单，用于查询退款日志获取退款单号
        },
        url: DomainName + '/WXWeChatRefundForMiniProgramsAction',
        success: function (data) {
          console.log(data);
          if (data.result_msg === "SUCCESS") {
            _this.$message({
              type: 'success',
              message: '退款提交成功!'
            });
            _this.getList1()
          } else if (data.result_msg === "PROCESSING") {
            _this.$message({
              type: 'success',
              message: '退款处理中!'
            });
            _this.getList1()
          } else if (data.result_code === "1011") {
            _this.$message({
              type: 'info',
              message: '该订单已全额退款！'
            });
            _this.getList1()
          } else {
            _this.$message({
              type: 'info',
              message: '退款失败！'
            });
          }
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
    },
    showMember(Sales_Order_SerialNumber) {
      sessionStorage.setItem("Sales_Order_SerialNumber", Sales_Order_SerialNumber)
      window.location.href = './show.html?Sales_Order_SerialNumber=' + Sales_Order_SerialNumber
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
      console.log(this.multipleSelection);
    },
  },
})